package org.ax.controller.plan;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.ax.data.Result;
import org.ax.pojo.plan.Custom;
import org.ax.pojo.plan.Order;
import org.ax.service.plan.CustomService;
import org.ax.service.plan.OrderService;
import org.ax.service.plan.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * 编程人:赵浩鑫
 * 时间:2021-02-25-20:30
 */
@RequestMapping("/order")
@RestController
public class OrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    CustomService customService;
    @Autowired
    ProductService productService;
    @RequestMapping("/find")
    public ModelAndView find(){
        return new ModelAndView("plan/order");
    }
    @Autowired
    Result result;
    @GetMapping("/list")
    public Result search(String status, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "6") int limit){
        Page<Order> orderPage = orderService.searchOrders(new Page(page, limit),status);
        result.setData(orderPage.getRecords());
        result.setCount(orderPage.getTotal());
        return result;
    }
    @PostMapping("/addOrder")
    public Result addOrder(Order order){
        result.setMsg(orderService.addOrder(order)?"添加成功":"添加失败");
        return result;
    }
    @PostMapping("/updateOrder")
    public Result updateOrder(Order order){
        result.setMsg(orderService.updateOrder(order)?"修改成功":"修改失败");
        return result;
    }
    @GetMapping("/patchDel")
    public Result patchDel(String[] orderId){
        result.setMsg(orderService.deletesCustom(orderId)?"删除成功":"删除失败");
        return result;
    }
    @GetMapping("/product")
    public Result product(){
        result.setData(productService.availableProduct());
        return result;
    }
    @GetMapping("/custom")
    public Result custom(){
        result.setData(customService.availableCustom());
        return result;
    }
}
